package dk.miljoeportalen.dkpunkt;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class JndiPlaceholderConfigurer extends PropertyPlaceholderConfigurer
		implements InitializingBean {

	private Context context;

	public void afterPropertiesSet() throws Exception {
		context = (Context) new InitialContext().lookup("java:comp/env");
	}

	protected String resolvePlaceholder(String placeholder, Properties props) {
		try {
			return (String) context.lookup(placeholder);
		}
		catch(Exception e) {
			return null;
		}
	}

}
